package com.quarantine.web;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.quarantine.service.TrendsManager;
import com.quarantine.web.CrudActionSupport;
import com.quarantine.model.trends;

@Namespace("/base")
public class TrendsAction extends CrudActionSupport<trends> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7579617689188959519L;
	private trends entity;
	private TrendsManager trends;
	private String id;
	private List<trends> trendsList;
	/**
	 * 分頁用
	 */
	private int currentpage;
	private int pageNo;
	public static final int pageSize = 20;
	private int prePage;
	private long totalPages;
	private int nextPage;
	private long allsize;

	/**
	 * 列出公告列表 
	 */
		@Override
		public String list() throws Exception {
			int pageSize = 10;
			Page<trends> page = new Page<trends>();
			page.setAutoCount(true);
			page.setPageNo(currentpage);
			page.setPageSize(pageSize);
		    trends.getList(page);
			setTrendsList(page.getResult());
			pageNo = page.getPageNo();
			prePage = page.getPrePage();
			nextPage = page.getNextPage();
			totalPages = page.getTotalPages();
			if(totalPages==0){
				
				pageNo=0;
			}
			allsize = page.getTotalCount();
			return "list";
		}

		@Override
		public String input() throws Exception {
			// TODO Auto-generated method stub
			return null;
		}
 
		/*
		 * 根据id获取对象并把点击率加一
		 */
		public String show() {
			Integer resetrate;
			entity = trends.getById(id);
			entity.setEditTime(entity.getEditTime());
			
			System.out.println(entity.getClickrate());
			resetrate = 1 + entity.getClickrate();
			entity.setClickrate(resetrate);
			trends.save(entity);
			return "detail"; // 待改
		}

	public trends getEntity() {
		return entity;
	}

	public void setEntity(trends entity) {
		this.entity = entity;
	}

	public TrendsManager getTrends() {
		return trends;
	}
	@Autowired
	public void setTrends(TrendsManager trends) {
		this.trends = trends;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<trends> getTrendsList() {
		return trendsList;
	}

	public void setTrendsList(List<trends> trendsList) {
		this.trendsList = trendsList;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPrePage() {
		return prePage;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public long getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(long totalPages) {
		this.totalPages = totalPages;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public long getAllsize() {
		return allsize;
	}

	public void setAllsize(long allsize) {
		this.allsize = allsize;
	}

	@Override
	public com.quarantine.model.trends getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		
	}

}
